Open
Conversation
Add missing `)` to docs.
Fixing example by adding `[` and `]` to provide list to hook
```
Error: nu::shell::invalid_config
× Encountered 1 error(s) when updating config
Error: nu::shell::type_mismatch
× Type mismatch at $env.config.hooks.env_change.PWD
╭─[]
4 │ env_change: {
5 │ ╭─▶ PWD: {
6 │ │ code: 'print $"changing directory from ($before) to ($after)"'
7 │ ├─▶ }
· ╰──── expected list<any>, but got record<code: string>
8 │ }
╰────
```
Author
|
Working example is now website at https://www.nushell.sh/book/hooks.html#hooks-as-strings currently shows broken example: |
Contributor
|
Are the parentheses even needed at all? This works but it will also overwrite your existing env_change.PWD if it already exists. $env.config = $env.config | upsert hooks {
env_change: {
PWD: [{
code: 'print $"changing directory from ($before) to ($after)"'
}]
}
} |
wsx7524999
approved these changes
Oct 5, 2025
Member
|
We should probably go further and update these to use the "modern" style: # Make sure the `PWD` hook list exists
$env.config.hooks.env_change.PWD = $env.config.hooks.env_change.PWD? | default []
# Add hook(s)
$env.config.hooks.env_change.PWD ++= [
{
condition: {|_, after| $after == /some/path/to/directory }
code: 'def foo [] { print "foo" }'
}
{
condition: {|before, _| $before == /some/path/to/directory }
code: 'hide foo'
}
]
$env.config.hooks.env_change.PWD ++= [
{
code: 'print $"changing directory from ($before) to ($after)"'
}
] |
|
I like to merged this pull request but how do I get access to the repository? |
Contributor
Only maintainers have access. If this PR gets updated similar to bahex's suggestion, we'll land it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add missing
)to docs.